<?php
/**
 * 
 * @author manhnv
 * @date: 03.04.2012
 * @email: manhnv@binhhoang.com
 *
 */
class modXosoArticlesCategoriesHelper
{
	static function &getList()
	{
		// Initialise variables.
		$list		= array();
		$items		= array();
		$db			= JFactory::getDbo();

		// Lấy ngày trong tuần 1-7 : CN -> TB
		$date		= strval(date('w') + 1);
				
		$query = $db->getQuery(true);
		$query->select('*');
		$query->from('#__categories');
		$query->where('published=1');
		$query->where("extension='com_content'");
		//$query->order('area ASC,ordering ASC');
		
		$list = $db->setQuery($query);
		$list = $db->loadObjectList();
		
		return $list;
	}
	
	static function &getCatTrees($parent_id = 1)
	{
		$db			= JFactory::getDbo();
		$query = $db->getQuery(true);
		$query->select('*');
		$query->from('#__categories');
		$query->where('published=1');
		$query->where("extension='com_content'");
		$query->where("parent_id=".$db->Quote($parent_id)."");
		$query->order('lft','ASC');
		//$query->order('area ASC,ordering ASC');
		
		$list = $db->setQuery($query);
		$arr = $db->loadObjectList();
		foreach($arr as $k => $v)
		{
			$query = $db->getQuery(true);
			$query->select('*');
			$query->from('#__categories');
			$query->where('published=1');
			$query->where("extension='com_content'");
			$query->where("parent_id=".$db->Quote($v->id)."");
			$query->order('lft','ASC');
			$sub = $db->setQuery($query);
			$sub = $db->loadObjectList();
			$arr[$k]->sub = $sub;
		}
        return $arr;
	}
	
	public function getTrees($parent_id = 1)
	{
		$db			= JFactory::getDbo();
		$query = $db->getQuery(true);
		$query->select('*');
		$query->from('#__categories');
		$query->where('published=1');
		$query->where("extension='com_content'");
		$query->where("parent_id=".$db->Quote($parent_id)."");
		//$query->order('area ASC,ordering ASC');
		
		$list = $db->setQuery($query);
		$arr = $db->loadObjectList();
		foreach($arr as $k => $v)
		{
			//$arr[$k]->sub = $this->getTrees($v->id);
		}
		return $arr;
	}
}
?>